package org.example.schoolbus.service.impl;
import org.example.schoolbus.mapper.LoginMapper;
import org.example.schoolbus.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class LoginServiceimpl implements LoginService {
    @Autowired
    private LoginMapper loginmapper;

    @Override
    public int LoginUser(String userphone, String userpassword) {
        Map<String,Object> map =loginmapper.LoginUser(userphone);
        if(map==null)//电话号码不存在，因为表中密码和电话号码不能为空
            return 1;
        else if (map.get("userpassword").equals(userpassword)&&loginmapper.UpdateStatues(userphone)>0) {
            return 2;//输入密码正确，状态更新成功
        }
        else if(map.get("userpassword").equals(userpassword)&&loginmapper.UpdateStatues(userphone)==0) {
            return 3;//输入密码正确，状态更新失败
        }
        return 0;//输入密码错误,更新成功
    }
}
